package com.muqiuhan.osmanthus.config

import org.springframework.beans.factory.annotation.{Qualifier, Value}
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.jdbc.DataSourceBuilder
import org.springframework.context.annotation.Bean
import org.springframework.stereotype.Component

import java.util.Date

@Component
case class Config():

  @Value("${osmanthus.node.id:1}") var nodeID: Long = 0

  @Value("${osmanthus.node.strategy:default}") var nodeStrategy: String = ""

  @Value("${osmanthus.node.fetchPeriod:100}") var fetchPeriod: Int = 0

  @Value("${osmanthus.node.fetchDuration:300}") var fetchDuration: Int = 0

  @Value("${osmanthus.pool.queueSize:1000}") var queueSize: Int = 0

  @Value("${osmanthus.pool.coreSize:5}") var corePoolSize: Int = 0

  @Value("${osmanthus.pool.maxSize:10}") var maxPoolSize: Int = 0

  @Value("${osmanthus.heartBeat.seconds:20}") var heartBeatSeconds: Int = 0

  @Value("${osmanthus.heartBeat.enable:true}") var heartBeatEnable: Boolean = false

  @Value("${osmanthus.recover.enable:true}") var recoverEnable: Boolean = false

  @Value("${osmanthus.recover.seconds:60}") var recoverSeconds: Int = 0

  @Bean(name = Array("osmanthusDataSource"))
  @Qualifier("osmanthusDataSource")
  @ConfigurationProperties(prefix = "osmanthus.datasource")
  inline def primaryDataSource: Any = DataSourceBuilder.create().build()

  var sysStartTime: Option[Date] = None

end Config
